import { login } from '@/api/user'
import { delToken, getToken, setToken } from '@/utils/storage'

export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    updateToken (state, token) {
      state.token = token
      setToken(token)
    },
    logout (state) {
      state.token = ''
      delToken()
    }
  },
  actions: {
    async loginAction (context, data) {
    //   console.log('loginAction')
      const res = await login(data)
      console.log(res.data.token)
      context.commit('updateToken', res.data.token)
    }
  },
  getters: {}
}
